<?php
/************************FoxPHP威客系统************************/
/*                                                            */
/*  FoxPHP.Com (C)2006-2016 FoxPHP Inc.                       */
/*  This is NOT a freeware, use is subject to license terms   */
/*  FoxPHP威客系统是商业软件,使用于商业用途请购买授权         */
/*  V3.0 2016.3                                               */
/*  foxphp@aliyun.com                                         */
/*  http://www.foxphp.com                                     */
/*                                                            */
/**************************************************************/

//发布任务类
namespace Task\Controller;
use Think\Controller;
class ShowController extends Controller{
	
	//单人流程
	public $processnamearr=array(1=>'待支付托管金',2=>'买家已支付托管金',3=>'待审核',4=>'进行中',5=>'暂投稿中',6=>'待选稿中',7=>'退款中',8=>'结束',9=>'关闭');
	
	//单人悬赏订单流程
	public $processorderarr=array(1=>'发布托管赏金',2=>'服务商交稿',3=>'雇主选稿',4=>'中标服务商交接',5=>'雇主验收付款',6=>'评价');
	
	//单人招标订单流程
	public $bidprocessorderarr=array(1=>'发布未托管',2=>'服务商投标',3=>'雇主选标并支付托管',4=>'中标服务商交接',5=>'雇主验收付款',6=>'评价');
	
	//计件订单流程
	public $numberprocessorderarr=array(1=>'发布托管赏金',2=>'服务商交稿',3=>'雇主选稿并支付',4=>'评价');
	
	public function CheckTask(){
		$id=intval($_GET['id']);
		$this->assign('id',$id);
		$this->assign('uid',$this->uid);
		$this->assign('uploadid','oid'); //设置上传文件任务字段
		
		$oid=intval($_GET['oid']);
		$this->assign('oid',$oid);
		
		if($id){
			$upload=new \Upload\Model\FileModel();
			$data=new \Data\Model\DataModel();
			$manage=$data->GetData($id);

			if(empty($manage['id'])){
				$this->error($data->getError());
				return false;
			}
			//发布任务状态
			//if(!$data->PublishTaskStatus($manage['process'])){
				//$this->error($data->getError(),U('/task/id/'.$id));
				//return false;
			//}
			
			$data->UpdateData($manage['id']);
			
			$taskfile=$upload->GetUploadFile('tid',$id);
			$this->assign('taskfile',$taskfile);
			
			$this->assign('task',$manage);
				
			$this->assign('PATH',array('任务',$manage['subject']));
			
			$this->assign('SEO',array('title'=>'￥'.($manage['money']/100).'元 '.$manage['subject'],'keywords'=>$manage['subject'],'description'=>$manage['description']));
			
			if($manage['task_number']==1){
				$order= M('DataOrder')->token(false)->where(" id=$id AND process=1 ")->find();
				
				if(!empty($order['oid'])){
					// 驳回数据
					$rejectData['seller_uid']=$order['seller_uid'];
					$rejectData['buyer_uid']=$order['buyer_uid'];
					$rejectData['task_id']=$id;
					$rejectList=M('reject')->where($rejectData)->order('time asc')->select();
					$this->assign('rejectList',$rejectList);
					
					//卖家
					$member=new \Member\Model\MemberModel();
					$member=$member->UidGetMember($order['seller_uid']);
					
					//获取稿件原件
					$orderfile=$upload->GetUploadFile('oid',$order['oid']);
					$this->assign('orderfile',$orderfile);
				}
			}
			
					
			//推荐8条
			$newtask=$data->GetCustomData(' type=1 AND task_mode<3 AND process>3 AND process<6 AND top>0','dateline DESC',8);
			$this->assign('newtask',$newtask);
			
			$model=new \Member\Model\MemberModel();
			$hotuser=$model->GetCustomData(' isshop=1 ','top DESC',8);
			$this->assign('hotuser',$hotuser);
		
			
			$this->assign('member',$member);
			$this->assign('order',$order);
			
			$uploadsize=round(C('onefileuploadsize')/1024/1024,2);
			$this->assign('uploadsize',$uploadsize);
			
			if($manage['task_mode']==2){
				$this->assign('processorderarr',$this->bidprocessorderarr);
			}else{
				if($manage['task_number']>1){
					$avatarsuccess=explode(',',$manage['avatar_success']);
					$this->assign('avatarsuccess',$avatarsuccess);
					$this->assign('processorderarr',$this->numberprocessorderarr);
				}else{
					$this->assign('processorderarr',$this->processorderarr);
				}
			}
		}
		
		return $manage;
	}
	
	public function indexAction(){

		$this->CheckTask();

		$this->display();
	}
	
	public function draftAction(){

		$this->CheckTask();

		$this->display();
	}
	
	//任务订单流程
	function UpdateTaskOrderProcess($process,$id){
		//$processtime='process_time'.$process;
		//return $this->Update('data',array(),array('process_order'=>$process,'process_order_name'=>$this->processorderarr[$process],"$processtime"=>$this->NowTime()),"WHERE id='$id'");
	}
	
	public function editAction(){

		$task=$this->CheckTask();
		if($task['process']!=4){
			$this->error('当前状态不能操作！');
			return false;
		}
		
		$oid=intval($_GET['oid']);
		$data=new \Data\Model\DataOrderModel();
		
		$draft=$data->GetDataOrder($oid);
		
		if(empty($draft['oid'])){
			$this->error('稿件不存在或当前状态不能操作！');
			return false;
		}
		
		$this->assign('draft',$draft);
		
		$this->display();
	}

	
}